package com.qingke.hibernate.dao;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.query.Query;

import com.qingke.hibernate.bean.Apartment;

public class ApartmentDAO extends SystemDAO{

	public ApartmentDAO(Session session) {
		super(session);
	}
	public List<Apartment> list(){
		Query<Apartment> query=session.createQuery("from Apartment", Apartment.class);
		return query.getResultList();
	}
	public Apartment getAccommodationById(int id){
		Query<Apartment> query=session.createQuery("from Apartment where id=:id", Apartment.class);
		query.setParameter("id", id);
		return query.getSingleResult();
	}
	public List<Apartment> getAccommodationsByBuilding(int building){
		Query<Apartment> query=session.createQuery("from Apartment where building=:building", Apartment.class);
		query.setParameter("building", building);
		return query.getResultList();
	}
	public List<Apartment> getAccommodationsByFloor(int floor){
		Query<Apartment> query=session.createQuery("from Apartment where floor=:floor", Apartment.class);
		query.setParameter("floor", floor);
		return query.getResultList();
	}
	public List<Apartment> getAccommodationsByRoom(int room){
		Query<Apartment> query=session.createQuery("from Apartment where room=:room", Apartment.class);
		query.setParameter("room", room);
		return query.getResultList();
	}
	public List<Apartment> getAccommodationsByBed(int bed){
		Query<Apartment> query=session.createQuery("from Apartment where bed=:bed", Apartment.class);
		query.setParameter("bed", bed);
		return query.getResultList();
	}

}
